﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace CC98.Xaml.Converters
{
    public class IntToVisibility : DependencyObject, IValueConverter
    {
        public object VisibleInt
        {
            get { return (object)GetValue(VisibleIntProperty); }
            set { SetValue(VisibleIntProperty, value); }
        }
        public static readonly DependencyProperty VisibleIntProperty =
            DependencyProperty.Register("VisibleInt", typeof(object), typeof(IntToVisibility), new PropertyMetadata(null));


        public object CollapsedInt
        {
            get { return (object)GetValue(CollapsedIntProperty); }
            set { SetValue(CollapsedIntProperty, value); }
        }
        public static readonly DependencyProperty CollapsedIntProperty =
            DependencyProperty.Register("CollapsedInt", typeof(object), typeof(IntToVisibility), new PropertyMetadata(null));

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var num = (int)value;

            if (this.VisibleInt != null)
            {
                if (num == (int)this.VisibleInt)
                {
                    return Visibility.Visible;
                }
                else
                {
                    return Visibility.Collapsed;
                }
            }

            if (this.CollapsedInt != null)
            {
                if (num == (int)this.CollapsedInt)
                {
                    return Visibility.Collapsed;
                }
                else
                {
                    return Visibility.Visible;
                }
            }

            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
